package com.zc.commons.auth.dto;

import com.zc.commons.auth.pojo.TenantUser;
import com.zc.commons.auth.pojo.SystemRole;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * 登录查询用户 UserDetails
 */
@Data
public class LoginUserDetails extends TenantUser implements UserDetails {

    private Set<SystemRole> roles;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.roles;
    }

    @Override
    public String getPassword() {
        return super.getPassword();
    }

    @Override
    public String getUsername() {
        return super.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !super.getIsFrozen();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return !super.getIsDeleted();
    }
}
